/* eslint-disable no-undef */
/* eslint-disable @typescript-eslint/no-require-imports */
const fs = require('fs')
const path = require('path')

// 创建 .vscode 文件夹
const vscodeFolderPath = path.join(__dirname, '.vscode')

if (fs.existsSync(vscodeFolderPath)) {
  fs.rmSync(vscodeFolderPath, { recursive: true, force: true })
}

fs.mkdirSync(vscodeFolderPath)
// 创建 extensions.json 文件并写入内容
const extensionsJsonPath = path.join(vscodeFolderPath, 'extensions.json')
const extensionsJsonContent = `{
  "recommendations": [
    "Vue.volar",
    "dbaeumer.vscode-eslint",
    "esbenp.prettier-vscode",
    "usernamehw.errorlens",
    "stylelint.vscode-stylelint",
    "lokalise.i18n-ally"
  ]
}`
fs.writeFileSync(extensionsJsonPath, extensionsJsonContent)

// 创建 settings.json 文件并写入内容
const settingsJsonPath = path.join(vscodeFolderPath, 'settings.json')
const settingsJsonContent = `{
  // 开启自动修复
  "editor.codeActionsOnSave": {
    "source.fixAll": "never",
    "source.fixAll.eslint": "explicit",
    "source.fixAll.stylelint": "explicit"
  },
  // 保存的时候自动格式化
  // "editor.formatOnSave": false,
  // 默认格式化工具选择prettier
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  // 配置该项，新建文件时默认就是space：2
  "editor.tabSize": 2,
  // stylelint校验的文件格式
  "stylelint.validate": [
    "css",
    "scss",
    "sass",
    "vue",
    "html"
  ],
  "files.associations": {
    "*.svg": "html"
  },
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "i18n-ally.localesPaths": ["src/language/packages"],
  "i18n-ally.keystyle": "nested",
  "i18n-ally.sortKeys": true,
  "i18n-ally.namespace": true,
  "i18n-ally.enabledParsers": ["ts"],
  "i18n-ally.sourceLanguage": "zh-CN",
  "i18n-ally.displayLanguage": "zh-CN",
  "i18n-ally.enabledFrameworks": ["vue"],
  "i18n-ally.encoding": "utf-8"
}`
fs.writeFileSync(settingsJsonPath, settingsJsonContent)
console.log('.vscode 文件夹及其内容已成功创建！')
